package com.lagou.orders.controller;

import com.lagou.domain.Orders;
import com.lagou.orders.feign.GoodsFeign;
import com.lagou.orders.service.OrdersService;
import com.lagou.vo.OrdersVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

@RequestMapping("orders")
@RestController
public class OrdersController {

    @Autowired
    private OrdersService ordersService;

    @Autowired
    private GoodsFeign goodsFeign;

    @GetMapping("getGoodsPort")
    public String getPort(){
        return goodsFeign.getPort();
    }

    @Value("${server.port}")
    private String port;

    @GetMapping("getOrderPort")
    public String getOrderPort(){
        return port;
    }

    @GetMapping("/getOrdersById/{id}")
    public Orders getOrdersById(@PathVariable Integer id){
        Orders orders = ordersService.getOrdersById(id);
        return orders;
    }

    @PostMapping("getOrderByPage")
    public Map<String,Object> getOrdersByPage(@RequestBody OrdersVO ordersVO){
        Map<String, Object> ordersByPage = ordersService.getOrdersByPage(ordersVO);
        return ordersByPage;
    }
}
